package com.example.myapplication;


import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.KeyEventDispatcher;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置布局
        setContentView(R.layout.activity_main);
        TextView viewById = findViewById(R.id.textView);
        viewById.setText("我叫皮蛋,嘿嘿,嘿嘿!!!");
        viewById.setTextSize(40);
        //获取id为PX的
        TextView px1 = findViewById(R.id.px1);
        px1.setTextColor(Color.RED);

        TextView dp = findViewById(R.id.dp);
        dp.setTextColor(Color.GREEN);
        //获取按键,
        Button button1 = findViewById(R.id.button);
        //设置按键事件
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //创建意图对象
                Intent intent = new Intent();
                //设置上下文,和跳转目的地,此处使用当前类,注意不能使用this,否则将是匿名内部类的this,
                intent.setClass(MainActivity.this, MainActivity2.class);
                //开始
                startActivity(intent);
            }
        });
        findViewById(R.id.imageView).setOnClickListener(this);
        findViewById(R.id.imageButton).setOnClickListener(this);
        findViewById(R.id.ButtonAndImage2).setOnClickListener(this);
        findViewById(R.id.jumping).setOnClickListener(this);
        findViewById(R.id.cycle).setOnClickListener(this);
        findViewById(R.id.exit).setOnClickListener(this);
        findViewById(R.id.jumping2).setOnClickListener(this);
        findViewById(R.id.jumping5).setOnClickListener(this);
        findViewById(R.id.jumping7).setOnClickListener(this);
        findViewById(R.id.jumping10).setOnClickListener(this);
        findViewById(R.id.jumping14).setOnClickListener(this);

        Log.d("MainActivity","创建");
    }

    @Override
    public void onClick(View v) {
        System.out.println("跳转");
        //创建意图对象
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.imageView:
                Intent intent2=new Intent(MainActivity.this, ImageViewActivity.class);
                //开始
                startActivity(intent2);
                break;
            case R.id.imageButton:
                //设置上下文,和跳转目的地,此处使用当前类,注意不能使用this,否则将是匿名内部类的this,
                intent.setClass(MainActivity.this, ImageButtonActivity3.class);
                //开始
                startActivity(intent);
                break;
            case R.id.ButtonAndImage2:
                //设置上下文,和跳转目的地,此处使用当前类,注意不能使用this,否则将是匿名内部类的this,
                ComponentName componentName = new ComponentName(this,ButtonAndImageActivity.class);
                //开始
                intent.setComponent(componentName);
                startActivity(intent);
                break;
            case R.id.jumping:
                //开始
                startActivity(new Intent(this,jumpingActivity.class));
                break;
            case R.id.cycle:
                //开始
                startActivity(new Intent(this,CycleActivity.class));
                break;
            case R.id.exit:
                //退出
                finish();
            case R.id.jumping2:
                //默认模式,点击到首页再返回必须回退所有才能实现退出
                startActivity(new Intent(this,jumping2Activity.class));
            case R.id.jumping5:
                //复用模式,点击到首页再返回将实现退出功能
                startActivity(new Intent(this, jumping3Activity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            case R.id.jumping7:
                //单例模式,
                startActivity(new Intent(this, jumping7Activity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP));
            case R.id.jumping10:
                //XML实现,复用模式
                startActivity(new Intent(this, jumping10Activity.class));
            case R.id.jumping14:
                //全局唯一模式,例如登录之后回退不再看见登录页面
                startActivity(new Intent(this, jumping12Activity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("Activity","销毁活动");
    }
}
